﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiWrkWorkingFrameDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CUiWrkWorkingFrameDlg : TxForm
{
  private RadioButton rdBtnNewWorkingFrame;
  private TxFrameEditBoxCtrl txFrmEditBoxNew;
  private RadioButton rdBtnReset;
  private Button btnOK;
  private Button btnCancel;
  private Container components;
  private CApWrkWorkingFrameApp m_app;

  public CUiWrkWorkingFrameDlg()
  {
    this.m_app = new CApWrkWorkingFrameApp();
    this.InitializeComponent();
    this.InitializeTxControls();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiWrkWorkingFrameDlg));
    this.rdBtnNewWorkingFrame = new RadioButton();
    this.txFrmEditBoxNew = new TxFrameEditBoxCtrl();
    this.rdBtnReset = new RadioButton();
    this.btnOK = new Button();
    this.btnCancel = new Button();
    ((Control) this).SuspendLayout();
    this.rdBtnNewWorkingFrame.Checked = true;
    componentResourceManager.ApplyResources((object) this.rdBtnNewWorkingFrame, "rdBtnNewWorkingFrame");
    this.rdBtnNewWorkingFrame.Name = "rdBtnNewWorkingFrame";
    this.rdBtnNewWorkingFrame.TabStop = true;
    this.txFrmEditBoxNew.EnableRelativeToWorkingFrameCoordinates = false;
    this.txFrmEditBoxNew.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txFrmEditBoxNew, "txFrmEditBoxNew");
    ((Control) this.txFrmEditBoxNew).Name = "txFrmEditBoxNew";
    this.txFrmEditBoxNew.PickLevel = (TxPickLevel) 6;
    this.txFrmEditBoxNew.ValidatorType = (TxValidatorType) 1;
    this.txFrmEditBoxNew.VisualizePickedFrameInGraphicViewer = false;
    this.txFrmEditBoxNew.InvalidFrameSet += new TxFrameEditBoxCtrl_InvalidFrameSetEventHandler(this.txFrmEditBoxNew_InvalidFrameSet);
    this.txFrmEditBoxNew.ValidFrameSet += new TxFrameEditBoxCtrl_ValidFrameSetEventHandler(this.txFrmEditBoxNew_ValidFrameSet);
    componentResourceManager.ApplyResources((object) this.rdBtnReset, "rdBtnReset");
    this.rdBtnReset.Name = "rdBtnReset";
    this.rdBtnReset.CheckedChanged += new EventHandler(this.rdBtnReset_CheckedChanged);
    this.btnOK.DialogResult = DialogResult.OK;
    componentResourceManager.ApplyResources((object) this.btnOK, "btnOK");
    this.btnOK.Name = "btnOK";
    this.btnOK.Click += new EventHandler(this.btnOK_Click);
    this.btnCancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.btnCancel, "btnCancel");
    this.btnCancel.Name = "btnCancel";
    this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
    ((Form) this).AcceptButton = (IButtonControl) this.btnOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.btnCancel;
    ((Control) this).Controls.Add((Control) this.btnCancel);
    ((Control) this).Controls.Add((Control) this.btnOK);
    ((Control) this).Controls.Add((Control) this.rdBtnReset);
    ((Control) this).Controls.Add((Control) this.txFrmEditBoxNew);
    ((Control) this).Controls.Add((Control) this.rdBtnNewWorkingFrame);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiWrkWorkingFrameDlg);
    ((Form) this).Closing += new CancelEventHandler(this.CUiWrkWorkingFrameDlg_Closing);
    ((Control) this).ResumeLayout(false);
  }

  private void InitializeTxControls()
  {
    TxTransformation lastPickedLocation = TxApplication.ActiveSelection.GetLastPickedLocation();
    if (TxTransformation.op_Inequality(lastPickedLocation, (TxTransformation) null))
      this.txFrmEditBoxNew.SetLocation(lastPickedLocation);
    this.txFrmEditBoxNew.ListenToPick = true;
    this.txFrmEditBoxNew.EnableRelativeToWorkingFrameCoordinates = false;
    this.txFrmEditBoxNew.Focus();
    ((Control) this.txFrmEditBoxNew).Select();
  }

  private void CUiWrkWorkingFrameDlg_Closing(object sender, CancelEventArgs e)
  {
    this.m_app.DeleteFrame();
    TxApplication.RefreshDisplay();
    this.txFrmEditBoxNew.ListenToPick = false;
    this.txFrmEditBoxNew.LoseFocus();
  }

  private void btnOK_Click(object sender, EventArgs e)
  {
    this.m_app.SetWorkingFrame(!this.rdBtnNewWorkingFrame.Checked ? new TxTransformation() : this.txFrmEditBoxNew.GetLocation());
    ((Form) this).Close();
  }

  private void rdBtnReset_CheckedChanged(object sender, EventArgs e)
  {
    if (this.rdBtnReset.Checked)
    {
      this.btnOK.Enabled = true;
      this.txFrmEditBoxNew.ListenToPick = false;
      this.txFrmEditBoxNew.LoseFocus();
      this.txFrmEditBoxNew.Enabled = false;
      TxTransformation lastPickedLocation = TxApplication.ActiveSelection.GetLastPickedLocation();
      if (TxTransformation.op_Inequality(lastPickedLocation, (TxTransformation) null))
        this.txFrmEditBoxNew.SetLocation(lastPickedLocation);
      else
        this.txFrmEditBoxNew.SetLocation(TxApplication.ActiveDocument.WorkingFrame);
      this.OnLocationChanged();
    }
    else
    {
      this.txFrmEditBoxNew.Enabled = true;
      this.txFrmEditBoxNew.ListenToPick = true;
      this.txFrmEditBoxNew.Focus();
      ((Control) this.txFrmEditBoxNew).Select();
    }
  }

  private void txFrmEditBoxNew_ValidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_ValidFrameSetEventArgs args)
  {
    if (!this.rdBtnNewWorkingFrame.Checked)
      return;
    this.btnOK.Enabled = true;
    this.OnLocationChanged();
  }

  private void txFrmEditBoxNew_InvalidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_InvalidFrameSetEventArgs args)
  {
    if (!this.rdBtnNewWorkingFrame.Checked)
      return;
    this.btnOK.Enabled = false;
  }

  private void btnCancel_Click(object sender, EventArgs e)
  {
    this.txFrmEditBoxNew.ListenToPick = false;
    this.txFrmEditBoxNew.LoseFocus();
    ((Form) this).Close();
  }

  private void OnLocationChanged()
  {
    this.m_app.AddWorkingFrameToGraphicViewer(this.txFrmEditBoxNew.GetLocation());
    TxApplication.RefreshDisplay();
  }
}
